//
//  YCQRGenerateViewController.m
//  DemoQRCode
//
//  Created by yunsheng on 15/7/13.
//  Copyright (c) 2015年 yunsheng. All rights reserved.
//

#import "YCQRGenerateViewController.h"

#import "QRCodeGenerator.h"
#import "YCQRCodeGenerator.h"

@interface YCQRGenerateViewController ()

@end

@implementation YCQRGenerateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.qrImgView.layer.borderColor = [UIColor grayColor].CGColor;
    self.qrImgView.layer.borderWidth = 1.0f;
    self.qrImgView.contentMode = UIViewContentModeScaleAspectFit;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)qrGenerateBtnClicked:(id)sender {
    [self.view endEditing:YES];
    
    self.qrStrSizeLabel.text = [NSString stringWithFormat:@"%@", @(self.qrTextField.text.length)];
    
    if (self.typeSegmentCtrl.selectedSegmentIndex == 0) {
        self.qrImgView.image = [QRCodeGenerator qrImageForString:self.qrTextField.text imageSize:self.qrImgView.bounds.size.width];
    } else {
        self.qrImgView.image = [YCQRCodeGenerator qrImageByCoreImageForString:self.qrTextField.text imageSize:self.qrImgView.bounds.size.width];
    }
}

- (IBAction)typeDidChange:(id)sender {
    self.qrImgView.image = nil;
}

@end
